﻿@{
    var id = Model != null ? Model.ID : 0;
}
@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Common.Enums.InsuranceWarranty
@using ZBJF.Warranty.WebProvider
@using ZBJF.Warranty.Common.Common
@using ZBJF.Warranty.Common.Enums.Base
@using ZBJF.Warranty.Common.Enums.Data
@using ZBJF.Warranty.Common.Enums.InsuranceProducts
@using ZBJF.Warranty.Model.ViewModel.AuditConfig
@model ZBJF.Warranty.Model.CellPhoneServiceProject

@section Header{
    @Styles.Render("~/Content/chosen")
}
<style>
    #modelTypeContent {
    padding-left:54px;
    }
    th {
        width: 120px;
        text-align: right;
    }

    h6 {
        display: inline;
    }

    button {
        width: 90px;
    }

    .btnContainer button :hover {
        border-color: aqua;
    }

    .fl {
        float: left;
    }

    .fr {
        float: right;
    }

    .mulSelectContainer {
        width: 300px;
    }

    .mulSelectTitle {
        border: 1px solid #ccc;
        border-bottom: none;
        background-color: #eee;
        border-radius: 4px 4px 0 0;
        padding: 3px 4px;
    }

    .mulSelect {
        width: 100%;
        min-height: 180px;
        border-radius: 0 0 4px 4px;
    }

    .selectAll {
        cursor: pointer;
    }

        .selectAll:hover {
            color: #0026cc;
        }

    .btnContainer {
        margin: 26px auto;
        padding-top: 20px;
        line-height: 35px;
    }
    #accessoriesLevelTable tr td {
    text-align:center;
    }
    #accessoriesLevelTable tr th {
    text-align:center;
    }
    .judgeTypeSelect {
    height:25px;
    }
</style>
<h4> &nbsp; &nbsp;手机维修服务</h4>

<ul id="myCondition" class="nav nav-tabs">
    <li class="active"><a href="#baseCondition" data-toggle="tab"> 基础承保条件</a></li>
    <li><a href="#advanceCondition" data-toggle="tab">高级承保条件</a></li>
    <li><a href="#collectProject" data-toggle="tab">信息收集项目配置</a></li>
    <li><a href="#auditProject" data-toggle="tab">信息审核项目配置</a></li>
</ul>
<form id="CellPhoneServiceProjectForm" name="CellPhoneServiceProjectForm">
    <div id="myConditionContent" class="tab-content">
        <!--基础承保条件-->
        <div class="tab-pane fade in active" id="baseCondition">
            <!--基本信息-->
            <p class="group-header">基本信息</p>
            <table class="table table-responsive table-bordered table-hover">
                <tr>
                    <th>服务项目：</th>
                    <td>
                        @Html.DropDownListFor(m => m.ServiceProjectId, ConvertToSelector.Instance.ServiceProjectConvertToSelectList((byte)ServiceProductType.CellPhoneRepair), new { validate = "{required:true,messages:{required:'请选择服务项目！'}}" })
                    </td>
                    <th>被保险设备类型：</th>
                    <td>
                        @Html.DropDownListFor(m => m.InsuranceDeviceType, ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(InsuranceOrderDeviceType)), new { @onchange = "Show()", validate = "{required:true,min:1,messages:{required:'请选择被保险设备类型！'}}" })
                    </td>
                    <th class="Show1">保额：</th>
                    <td class="Show1">
                        @Html.TextBoxFor(m => m.InsuredAmount, new { maxlength = 8, @class = "input-small", onkeyup = "onlyInputDecimal(this)", validate = "{required:true,messages:{required:'请输入保额！'}}" }) 元
                    </td>
                    <th class="Show1">新机投保期限：</th>
                    <td class="Show1">
                        @Html.TextBoxFor(m => m.NewMachineInsuranceTimeLimit, new { maxlength = 5, @class = "input-small", onkeyup = "onlyInputInt(this,0)", validate = "{required:true,min:1,messages:{required:'请输入新机投保期限！'}}" }) 天
                    </td>
                    <th>服务次数：</th>
                    <td>
                        @Html.TextBoxFor(m => m.ServiceTimes, new { maxlength = 5, @class = "input-small", onkeyup = "onlyInputInt(this,0)", validate = "{required:true,messages:{required:'请输入服务次数！'}}" })<span> 次</span>
                    </td>
                </tr>
            </table>
            <!--维修配件类型-->
            <p class="group-header ">维修配件类型</p>
            <table class="keep-all">
                <tr>
                    <td>配件类型：</td>
                    <td>
                        @Html.DropDownList("AccessoriesTypeId", ConvertToSelector.Instance.AccessoriesTypeConvertToSelectList(1))
                    </td>
                    <td>配件等级：</td>
                    <td>
                        <select id="AccessoriesLevelId">
                            <option value="">请选择</option>
                        </select>
                    </td>
                    <td>
                        <a class="btn btn-info margin-10" href="javascript:void(0)" id="addAccessories">添加为可用配件</a>
                    </td>
                </tr>
            </table>
            <table class="table table-responsive table-bordered table-hover" id="accessoriesLevelTable" style="display:none;">
                <thead>
                    <tr>
                        <th>序号</th>
                        <th>配件类型</th>
                        <th>配件等级</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
            <!--可提供的维修方式-->
            <p class="group-header ">可提供的维修方式</p>
            <div>
                @{bool staus = true; }
                @foreach (var item in ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(ZBJF.Warranty.Common.Enums.InsuranceWarranty.InsuranceWarrantyMaintenanceType)))
            {
                staus = false;
                if (item.Value != "")
                {
                    //if (Model != null && Model.InsuranceProductWarrantyMaintenanceTypes != null)
                    //{
                    //    staus = Model.InsuranceProductWarrantyMaintenanceTypes.Any(o => o.InsuranceWarrantyMaintenanceTypeId.ToString() == item.Value);
                    //}
                    <label>
                        <input name="InsuranceWarrantyMaintenanceTypeId" type="checkbox" class="insuranceWarrantyMaintenanceTypeId" value="@item.Value" @(staus ? "checked = true" : "")>@item.Text
                    </label>
                }
            }
            </div>
        </div>
        <!--高级承保条件-->
        <div class="tab-pane fade" id="advanceCondition">
            <p class="group-header ">本保险产品承保满足以下条件的设备</p>
            <div>
                <h6>条件1：</h6>
                当被保险设备
                <select id="ModelTypeJudgeType" name="ModelTypeJudgeType" class="judgeTypeSelect">
                    <option value="1">是</option>
                    <option value="2">不是</option>
                </select>
                选定的型号时
                <span style="float:right;"> @Html.CheckBoxFor(m => m.UseModelTypeOption) 启用本条件</span>
                <div style="clear:both"></div>
            </div>
            <div @(Model == null || !Model.UseModelTypeOption ? "style=display:none;" : "") id="modelTypeContent">
                <div class="control-group">
                    <label class="control-label">品牌名称：</label>
                    <div class="controls">
                        <select id="productBrands" style="min-width:120px;">
                            <option value="0">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">型号：</label>
                    <div class="controls" style="width:700px;">

                        <div class="mulSelectContainer fl">
                            <div class="mulSelectTitle">
                                <span>可选型号</span>
                            </div>
                            <select multiple="multiple" id="productModels" class="mulSelect"></select>
                        </div>
                        <div style="width:98px;float:left; text-align:center;">
                            <div class="btnContainer">
                                <div>
                                    <a id="selectModelAll">全部选择 >></a>
                                </div>
                                <div>
                                    <a id="selectModel">选择 ></a>
                                </div>
                                <div>
                                    <a id="cancelModel">< 取消</a>
                                </div>
                                <div>
                                    <a id="cancelModelAll"><< 全部取消</a>
                                </div>
                            </div>
                        </div>
                        <div class="mulSelectContainer fr">
                            <div class="mulSelectTitle">
                                <span>已选型号</span>
                            </div>
                            <select multiple="multiple" id="productModelsSelected" class="mulSelect">
                                @{
                                var availableModel = ServiceFactory.InsuranceProductsAvailableModelTypeServiceInstance.GetInsuranceProductAvailableModel(id);
                                }
                                @foreach (var item in availableModel)
                            {
                                    <option value="@item.ModelID" productbrandsid="@item.BrandID" productmodelsname="@item.ModelName">@(item.BrandName)_@item.ModelName</option>
                            }
                            </select>
                            <input type="hidden" value="" name="availableModelType" id="availableModelType" />
                        </div>

                        <div style="clear:both"></div>
                    </div>
                </div>
            </div>

            <div>
                <h6>条件2：</h6>
                当屏幕类型
                <select id="ScreenTypeJudgeType" name="ScreenTypeJudgeType" class="judgeTypeSelect">
                    <option value="1">是</option>
                    <option value="2">不是</option>
                </select>
                选定的屏幕类型时
                <span style="float:right;">@Html.CheckBoxFor(m => m.UseScreenTypeOption) 启用本条件</span>
                <div style="clear:both"></div>
            </div>
            <div @(Model == null || !Model.UseScreenTypeOption ? "style=display:none" : "") id="screenTypeContent">
                <div class="control-group" style="padding-left:51px;" id="availableScreenTypeDiv">
                    @{
                    var availableScreenType = ServiceFactory.InsuranceProductsAvailableScreenTypeServiceInstance.GetInsuranceProductsAvailableScreenTypeList(Model == null ? 0 : Model.ID);
                    }
                    @foreach (var item in ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(ZBJF.Warranty.Common.Enums.Data.ScreenTypeEnum), 0, false))
                {
                    staus = false;
                    if (availableScreenType != null)
                    {
                        staus = availableScreenType.Any(o => o.ScreenTypeCode.ToString() == item.Value);
                    }
                    <label>
                        <input name="AvailableScreenType" type="checkbox" value="@item.Value" @(staus ? "checked = true" : "")> @item.Text
                    </label>
                }
                </div>
            </div>
            <div>
                <h6>条件3：</h6>当被保险设备的价格介于
                @if (Model == null || !Model.UsePriceOption)
            {
                    @Html.TextBoxFor(m => m.ProductAmountFrom, new { maxlength = 8, @class = "input-small", onkeyup = "onlyInputDecimal(this,2)", disabled = "disabled" })
            }
            else
            {
                    @Html.TextBoxFor(m => m.ProductAmountFrom, new { maxlength = 8, @class = "input-small", onkeyup = "onlyInputDecimal(this,2)" })
            }
                -
                @if (Model == null || !Model.UsePriceOption)
            {
                    @Html.TextBoxFor(m => m.ProductAmountTo, new { maxlength = 8, @class = "input-small", onkeyup = "onlyInputDecimal(this,2)", disabled = "disabled" })
            }
            else
            {
                    @Html.TextBoxFor(m => m.ProductAmountTo, new { maxlength = 8, @class = "input-small", onkeyup = "onlyInputDecimal(this,2)" })
            }
                元时
                <span style="float:right;">@Html.CheckBoxFor(m => m.UsePriceOption) 启用本条件</span>
            </div>
        </div>
        <!--信息收集项目配置-->
        <div class="tab-pane fade" id="collectProject">
            <div class="categoryTree">
                <table class="table table-responsive table-bordered table-hover" id="infoCollectTable">
                    <thead>
                        <tr>
                            <th></th>
                            <th>信息收集项目</th>
                            <th>资料类别</th>
                            <th>可上传图片数</th>
                            <th>是否必填</th>
                            <th>启用</th>
                        </tr>
                    </thead>
                    <tbody>
                        @Html.Action("InfoCollectSelect", "InsuranceProducts", new { listPage = ViewBag.allInfoCollectModel, pid = 0, layer = 0 })
                    </tbody>
                </table>
            </div>
        </div>
        <!--信息审核项目配置-->
        <div class="tab-pane fade" id="auditProject">
            <div class="categoryTree">
                <table class="table table-responsive table-bordered table-hover" id="auditProjectConfigurationTable">
                    <thead>
                        <tr>
                            <th></th>
                            <th>信息审核项目</th>
                            <th>字段类型</th>
                            <th>是否必填</th>
                            <th>启用</th>
                        </tr>
                    </thead>
                    <tbody>
                        @Html.Action("AuditProjectConfigurationSelect", "InsuranceProducts", new { listPage = ViewBag.allAuditModel, pid = 0, layer = 0 })
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</form>
<div style="text-align: center;">
    <input class="btn btn-primary Edit-R" type="button" value="保存" onclick="loading(this)" />
    <input class="btn btn-primary Edit-R" type="button" value="关闭" onclick="closeCellPhoneFrom()" />
    <input class="btn" type="button" value="重置" onclick="resetCellPhoneFrom()">
</div>
@section scripts
{
    @Scripts.Render("~/bundles/chosen")
    @Scripts.Render("~/bundles/permission")
    <script type="text/javascript">
        //let cellPhoneServiceProject = []; //已添加手机维修服务列表
        let tagCellPhoneIndex = -1; //记录当前编辑的服务项目在table中的索引号。 用于保存的时候删除旧的数据

        //手机维修页面加载完执行
        function cellPhoneOnload() {
            Show();
            $("#ProductName").blur(function () {
                if (isExistInsuranceProducts(this.value, $("#ID").val())) {
                    layer.alert("产品名称已存在，请修改");
                }
            });
            //=====================================基础承保条件START=======================
            //配件类型选择，获取配件等级
            $("#AccessoriesTypeId").change(function () {
                let _value = $(this).val();
                if (!_value) {
                    $("#AccessoriesLevelId").html("<option value=''>请选择</option>");
                    return;
                }
                $.ajax({
                    type: "GET",
                    url: "/AccessoriesLevel/GetAccessoriesLevel",
                    dataType: "json",
                    data: { AccessoriesTypeIds: _value },
                    success: function (data) {
                        if (!data.Result) {
                            alert("初始化数据失败");
                            return;
                        }
                        var _data = data.Data;
                        var _html ="<option value=''>请选择</option>";
                        if (_data && _data.length > 0) {
                            _data.forEach(function (item) {
                                _html += "<option value='" + item["ProductTypeId"]+"|"+item["AccessoriesTypeId"]+"|"+item["ID"] + "'>" + item["AccessoriesLevelName"] + "</option>";
                            })
                        }
                        $("#AccessoriesLevelId").html(_html);
                    }
                });

            })
            //添加为可用配件
            $("#addAccessories").on("click", function () {
                var _data = {};
                _data.AccessoriesTypeName = $("#AccessoriesTypeId option:selected").html();
                _data.AccessoriesLevelName = $("#AccessoriesLevelId option:selected").html();
                _data.AccessoriesLevelId = $("#AccessoriesLevelId option:selected").val();
                if (!_data.AccessoriesLevelId) {
                    layer.alert("请选择配件等级");
                    return;
                }
                //判断是否重复添加
                var accessoriesLevelList = $(".accessoriesLevelList");
                if (accessoriesLevelList && accessoriesLevelList.length > 0) {
                    for (let i = 0, j = accessoriesLevelList.length; i < j; i++) {
                        if (_data.AccessoriesLevelId == $(accessoriesLevelList[i]).attr("dataValue")) {
                            layer.alert("请勿重复添加配件等级");
                            return;
                        }
                    }
                }
                //生成html数据
                let _html = '<tr class="accessoriesLevelList" dataValue="' + _data.AccessoriesLevelId + '">';
                _html += '<td>' + (accessoriesLevelList.length + 1) + '</td>';
                _html += '<td>' + _data.AccessoriesTypeName + '</td>';
                _html += '<td>' + _data.AccessoriesLevelName + '</td>';
                _html += '<td><a href="#" onclick="deleteAccessoriesLevel(this)">删除</a></td>';
                _html += '</tr>';
                $("#accessoriesLevelTable tbody").append(_html);
                $("#accessoriesLevelTable").show(500);

            })

            //=====================================基础承保条件END=========================

            //=====================================高级承保条件START=======================
            //启用机型条件
            $("#UseModelTypeOption").on("change", function () {
                if ($(this).is(":checked")) {
                    $("#modelTypeContent").show();
                }
                else {
                    $("#modelTypeContent").hide();
                }
            })
            //启用屏幕类型条件
            $("#UseScreenTypeOption").on("change", function () {
                if ($(this).is(":checked")) {
                    $("#screenTypeContent").show();
                }
                else {
                    $("#screenTypeContent").hide();
                }
            })
            //启用价格区间条件
            $("#UsePriceOption").on("change", function () {
                if ($(this).is(":checked")) {
                    $("#ProductAmountFrom").removeAttr("disabled");
                    $("#ProductAmountTo").removeAttr("disabled");
                }
                else {
                    $("#ProductAmountFrom").attr("disabled", "disabled");
                    $("#ProductAmountTo").attr("disabled", "disabled");
                }
            })

            //设置高级承保条件中的品牌
            setSelectData("/ProductBrands/GetProductBrands", "GET", "productBrands", { ProductTypeId: 1 }, "ID", "BrandName", true);

            //选择品牌事件
            $("#productBrands").on("change", function () {
                var _productBrandsId = $(this).val();
                if (!_productBrandsId || _productBrandsId == "0") {
                    $("#productModels").html("");
                    return;
                }

                //获取已选型号的ID
                var _options = $("#productModelsSelected option[productBrandsId='" + _productBrandsId + "']");
                var ids = "";
                for (var i = 0, j = _options.length; i < j; i++) {
                    var item = $(_options[i]);
                    if (i == 0) {
                        ids += item.val();
                    } else {
                        ids += "," + item.val();
                    }
                }
                //设置型号
                setSelectData("/ProductModels/GetProductModels", "POST", "productModels", { ProductBrandsId: _productBrandsId, Ids: ids }, "ID", "ModelName", false);
            })

            //-------------------------------------型号START--------------------------------
            //选择型号
            $("#selectModel").on("click", function () {
                var selectedOption = $("#productModels option:selected");
                if (!selectedOption || selectedOption.length < 1) {
                    layer.alert("请至少选择一项");
                    return;
                }
                var _productTypeName = $("#productBrands option:selected").html() + "_";
                var _productTypeId = $("#productBrands option:selected").val();
                for (var i = 0, j = selectedOption.length; i < j; i++) {
                    var item = $(selectedOption[i]);
                    item.attr("productBrandsId", _productTypeId);
                    item.attr("productModelsName", item.html());
                    //item.removeAttr("selected");
                    item.html(_productTypeName + item.html());
                }
                $("#productModelsSelected").append(selectedOption);
            })
            //全选型号
            $("#selectModelAll").on("click", function () {
                var selectedOption = $("#productModels option");
                if (!selectedOption || selectedOption.length < 1) {
                    layer.alert("请至少选择一项");
                    return;
                }
                var _productBrandsName = $("#productBrands option:selected").html() + "_";
                var _productBrandsId = $("#productBrands option:selected").val();
                for (var i = 0, j = selectedOption.length; i < j; i++) {
                    var item = $(selectedOption[i]);
                    item.attr("productBrandsId", _productBrandsId);
                    item.attr("productModelsName", item.html());
                    item.attr("selected", "selected");
                    item.html(_productBrandsName + item.html());
                }
                $("#productModelsSelected").append(selectedOption);
            })
            //取消型号
            $("#cancelModel").on("click", function () {
                var selectedOption = $("#productModelsSelected option:selected");
                if (!selectedOption || selectedOption.length < 1) {
                    layer.alert("请至少选择一项");
                    return;
                }
                var _productBrandsId = $("#productBrands option:selected").val();
                for (var i = 0, j = selectedOption.length; i < j; i++) {
                    var item = $(selectedOption[i]);
                    //item.removeAttr("selected");
                    item.html(item.attr("productModelsName"));

                    var id = item.attr("productBrandsId");
                    if (id == _productBrandsId) {
                        $("#productModels").append(item);
                    } else {
                        item.remove();
                    }
                }
            })
            //全部取消型号
            $("#cancelModelAll").on("click", function () {
                var selectedOption = $("#productModelsSelected option");
                if (!selectedOption || selectedOption.length < 1) {
                    layer.alert("请至少选择一项");
                    return;
                }
                var _productBrandsId = $("#productBrands option:selected").val();
                for (var i = 0, j = selectedOption.length; i < j; i++) {
                    var item = $(selectedOption[i]);
                    item.attr("selected", "selected");
                    item.html(item.attr("productModelsName"));
                    var id = item.attr("productBrandsId");
                    if (id == _productBrandsId) {
                        $("#productModels").append(item);
                    } else {
                        item.remove();
                    }
                }
            })
            //-------------------------------------型号END----------------------------------
            //====================================高级承保条件END=======================
        }
        //重置表单
        function resetCellPhoneFrom() {
            document.getElementById("CellPhoneServiceProjectForm").reset();
            $("#NewMachineInsuranceTimeLimit").attr("disabled", "disabled");
            //清空维修配件类型
            $("#accessoriesLevelTable tbody").html("");
            $("#accessoriesLevelTable").hide();
            //关闭高级承保条件disabled
            $("#productModels").html("");
            $("#productModelsSelected").html("");
            $("#modelTypeContent").hide();
            $("#screenTypeContent").hide();
            $("#ProductAmountFrom").attr("disabled", "disabled");
            $("#ProductAmountTo").attr("disabled", "disabled");
            $('input:checkbox').prop('checked', false);
            //关闭项目配置
            $(".close").click();
        }
        //表单提交
        function loading(_this) {
            if ($("#CellPhoneServiceProjectForm").valid()) {
                let _data = {};
                _data.InsuranceDevice = 1;
                _data.ServiceProjectId = $("#ServiceProjectId").val();
                if (!_data.ServiceProjectId) {
                    layer.alert("请选择服务项目");
                    return;
                } else if (tagCellPhoneIndex<0) { //不是修改需要判断是否重复添加
                    //不可添加相同的服务项目
                    let temp = $("#serviceProjectList tr[ServiceProjectId='" + _data.ServiceProjectId + "']");
                    if (temp && temp.length > 0)
                    {
                        layer.alert("已添加过的服务项目，请重新选择服务项目");
                        return;
                    }
                }
                _data.InsuranceDeviceType =$("#InsuranceDeviceType").val();
                if (!_data.InsuranceDeviceType) {
                    layer.alert("请选择被保险设备类型");
                    return;
                }
                _data.InsuredAmount = $("#InsuredAmount").val();
                if (!_data.InsuredAmount) {
                    layer.alert("请输入保额");
                    return;
                }
                _data.NewMachineInsuranceTimeLimit = $("#NewMachineInsuranceTimeLimit").val();
                if (_data.InsuranceDeviceType == "1" && !_data.NewMachineInsuranceTimeLimit) {
                    layer.alert("请输入新机投保期限");
                    return;
                }
                _data.ServiceTimes = $("#ServiceTimes").val();
                if (!_data.ServiceTimes) {
                    layer.alert("请输入服务次数");
                    return;
                }
                //维修配件类型
                _data.AccessoriesLevelList = [];
                var accessoriesLevelList = $(".accessoriesLevelList");
                if (!accessoriesLevelList || accessoriesLevelList.length < 1) {
                    layer.alert("请添加维修配件类型");
                    return;
                }
                for (let i = 0, j = accessoriesLevelList.length; i < j; i++) {
                    let accessoriesLevel = {};
                    let _av = $(accessoriesLevelList[i]).attr("dataValue").split('|');
                    if (_av.length != 3)
                    {
                        layer.alert("配件类型信息错误");
                        return;
                    }
                    accessoriesLevel.ProductTypeID = _av[0];
                    accessoriesLevel.AccessoriesTypeID = _av[1];
                    accessoriesLevel.AccessoriesLevelID = _av[2];
                    _data.AccessoriesLevelList.push(accessoriesLevel);
                }
                _data.AccessoriesLevelHtml = $("#accessoriesLevelTable tbody").html();//保存维修配件类型html数据， 可用于编辑

                //可提供的维修方式
                _data.InsuranceWarrantyMaintenanceTypeList = [];
                var insuranceWarrantyMaintenanceTypeList = $(".insuranceWarrantyMaintenanceTypeId:checked");
                if (!insuranceWarrantyMaintenanceTypeList || insuranceWarrantyMaintenanceTypeList.length < 1) {
                    layer.alert("请选择可提供的维修方式");
                    return;
                }
                for (let i = 0, j = insuranceWarrantyMaintenanceTypeList.length; i < j; i++) {
                    _data.InsuranceWarrantyMaintenanceTypeList.push($(insuranceWarrantyMaintenanceTypeList[i]).val() - 0);
                }


                //三个高级承保条件， 勾选启用条件就必须设置
                _data.UseModelTypeOption = $("#UseModelTypeOption").is(":checked");
                _data.ModelTypeJudgeType = $("#ModelTypeJudgeType").val();
                if (_data.UseModelTypeOption) {
                    //设置可保型号信息
                    let modelOption = $("#productModelsSelected option");

                    _data.ModelsHtml = $("#productModelsSelected").html();//保存已选型号html数据， 可用于编辑

                    let strModelsSelected = [];
                    if (modelOption && modelOption.length > 0) {
                        for (let i = 0; i < modelOption.length ; i++) {
                            strModelsSelected.push($(modelOption[i]).val() - 0);
                        }
                    }
                    if (strModelsSelected.length < 1) {
                        layer.alert("请选择可承保型号");
                        return;
                    }
                    _data.InsuranceProductsAvailableModelType = strModelsSelected;
                }
                _data.UseScreenTypeOption = $("#UseScreenTypeOption").is(":checked");
                _data.ScreenTypeJudgeType = $("#ScreenTypeJudgeType").val();
                if (_data.UseScreenTypeOption) {
                    var screenTypeSelected = $("#availableScreenTypeDiv").find("input[type='checkbox'][name='AvailableScreenType']:checked");
                    if (!screenTypeSelected || screenTypeSelected.length < 1) {
                        layer.alert("请选择可承保屏幕类型");
                        return;
                    }
                    _data.InsuranceProductsAvailableScreenType = [];
                    for (let i = 0; i < screenTypeSelected.length ; i++) {
                        _data.InsuranceProductsAvailableScreenType.push($(screenTypeSelected[i]).val() - 0);
                    }
                }
                _data.UsePriceOption = $("#UsePriceOption").is(":checked");
                if (_data.UsePriceOption) {
                    var productAmountFrom = $("#ProductAmountFrom").val();
                    var productAmountTo = $("#ProductAmountTo").val();

                    if (productAmountFrom == "" || productAmountTo == "") {
                        layer.alert("请输入完整的产品价格范围");
                        return;
                    } else if (parseInt(productAmountFrom) > parseInt(productAmountTo)) {
                        layer.alert("产品价格范围不正确（后面的价格必须大于前面的价格）");
                        return;
                    }
                    _data.ProductAmountFrom = productAmountFrom;
                    _data.ProductAmountTo = productAmountTo;
                }
                //信息收集项目配置
                _data.InsuranceProductsInfoCollectItemMappings = [];
                let useInfoCollect = $(".useInfoCollect:checked");
                if (useInfoCollect && useInfoCollect.length > 0) {
                    for (let i = 0, j = useInfoCollect.length; i < j; i++) {
                        let item = $(useInfoCollect[i]);
                        let infoCollectItem = {};
                        infoCollectItem.CollectTypeCollectItemMappingID = item.val();
                        infoCollectItem.IsMust = item.parent("td").parent("tr").find(".infoCollectIsMust").is(":checked");
                        infoCollectItem.CanUploadPicCount = item.parent("td").parent("tr").find(".infoCollectNumber").val();
                        if (!infoCollectItem.CanUploadPicCount) {
                            layer.alert("请填写可上传图片数");
                            return;
                        }
                        _data.InsuranceProductsInfoCollectItemMappings.push(infoCollectItem);
                    }
                }
                //审核项目配置
                _data.InsuranceProductsAuditProjectConfigurationMappings = [];
                let useAuditProject = $(".useAuditProject:checked");
                if (useAuditProject && useAuditProject.length > 0) {
                    for (let i = 0, j = useAuditProject.length; i < j; i++) {
                        let item = $(useAuditProject[i]);
                        let auditProjectItem = {};
                        auditProjectItem.AuditProjectConfigurationID = item.val();
                        auditProjectItem.IsMust = item.parent("td").parent("tr").find(".auditProjectIsMust").is(":checked");
                        _data.InsuranceProductsAuditProjectConfigurationMappings.push(auditProjectItem);
                    }
                }
                let _index = ($("#serviceProjectList .serviceProjectItem").length + 1);
                console.log(_data)
                console.log(JSON.stringify(_data))
                _data.ServiceProjectName= $("#ServiceProjectId option:selected").text();
                let _html = setServiceProjectHtml(_data);
                if (tagCellPhoneIndex > -1) {
                    $("#serviceProjectList tr").eq(tagCellPhoneIndex).remove();
                    if (tagCellPhoneIndex == 0) {
                        $("#serviceProjectList tr").eq(0).before(_html).find(".noService").hide();
                    }
                    else {
                        $("#serviceProjectList tr").eq(tagCellPhoneIndex - 1).after(_html).find(".noService").hide();
                    }
                    tagCellPhoneIndex = -1;
                }
                    else {
                        $("#serviceProjectList").append(_html).find(".noService").hide();
                }
                $("#cellPhoneRepairService").hide();
                resetCellPhoneFrom();
            }
        }

        //判断产品名称是否存在
        function isExistInsuranceProducts(productName) {
            var result = false;
            $.ajax({
                url: "/InsuranceProducts/IsExistInsuranceProducts?productName=" + productName,
                async: false,
                success: function (data) {
                    result = data == "True";
                }
            });
            return result;
        }
        //是否隐藏新机投保期限
        function Show() {
            var id = $("#InsuranceDeviceType option:selected").val();
            if (id == 1) {
                $("#NewMachineInsuranceTimeLimit").removeAttr("disabled").attr("validate", "{required:true,min:1,messages:{required:'请输入新机投保期限！'}}");
            } else {
                $("#NewMachineInsuranceTimeLimit").val("").attr("disabled", true).attr("validate", "{required:false}");
            }
        }

        //选中客户后设置值,清空选中的配件
        function reloadAfterTime(time) {
            setTimeout(function () { location.reload() }, time || 666);
        };

        //获取设备类型; 数据后台地址 | 请求方式（post/get） | select标签的ID | 请求参数 | Value对应的字段名称 | Text对应的字段名称 | 是否有默认选项 true/false
        function setSelectData(url, postType, selectId, params, valueName, textName, hasDefault) {
            //加载所有的带接入列表
            $.ajax({
                type: postType,
                url: url,
                dataType: "json",
                data: params,
                success: function (data) {
                    if (!data.Result) {
                        alert("初始化数据失败");
                        return;
                    }
                    var _data = data.Data;
                    var _html = "";
                    if (hasDefault == true) {
                        _html += "<option value=''>请选择</option>";
                    }
                    if (_data && _data.length > 0) {
                        _data.forEach(function (item) {
                            _html += "<option value='" + item[valueName] + "'>" + item[textName] + "</option>";
                        })
                    }
                    $("#" + selectId).html(_html);
                }
            });
        }

        //设置可提供的配件类型
        function setInsuranceProductScreenSPs(url, postType, selectId, params, valueName, textName) {
            //加载所有的带接入列表
            $.ajax({
                type: postType,
                url: url,
                dataType: "json",
                data: params,
                success: function (data) {
                    if (!data.Result) {
                        alert("初始化数据失败");
                        return;
                    }
                    var _data = data.Data;
                    var _html = "";
                    if (_data && _data.length > 0) {
                        _data.forEach(function (item) {
                            _html += "<label>";
                            _html += '    <input name="InsuranceProductScreenSPTypeId" type="checkbox" value="' + item[valueName] + '">' + item[textName];
                            _html += " </label>";
                        })
                    }
                    $("#" + selectId).html(_html);
                }
            });
        }

        //删除维修配件类型
        function deleteAccessoriesLevel(_this) {
            $(_this).parent("td").parent("tr").remove();

            //如果没有数据了就要隐藏table
            if ($("#accessoriesLevelTable tbody tr").length < 1) {
                $("#accessoriesLevelTable").hide(500);
            }
        }

        //关闭手机服务框
        function closeCellPhoneFrom() {
            resetCellPhoneFrom();
            $("#cellPhoneRepairService").hide();
        }

        //生成手机维修服务表单数据_用于修改
        function setCellPhoneFrom(_data,trIndex)
        {
            tagCellPhoneIndex = trIndex;
            $("#cellPhoneRepairService").show();
            $("#ServiceProjectId").val(_data.ServiceProjectId); //服务项目
            $("#InsuranceDeviceType").val(_data.InsuranceDeviceType); //被保险设备类型
            $("#NewMachineInsuranceTimeLimit").val(_data.NewMachineInsuranceTimeLimit); //新机投保期限
            if (_data.InsuranceDeviceType == 1)
            {
                $("#NewMachineInsuranceTimeLimit").removeAttr("disabled");
            }
            $("#ServiceTimes").val(_data.ServiceTimes); //服务次数
            $("#InsuredAmount").val(_data.InsuredAmount);
            //维修配件类型
             $("#accessoriesLevelTable").show();
             $("#accessoriesLevelTable tbody").html(_data.AccessoriesLevelHtml);

            //可提供的维修方式
             for(let i=0,j=_data.InsuranceWarrantyMaintenanceTypeList.length;i<j;i++)  
             {
                 $(".insuranceWarrantyMaintenanceTypeId[value='" + _data.InsuranceWarrantyMaintenanceTypeList[i] + "']").prop("checked", "true");
             }

            //三个高级承保条件， 勾选启用条件就必须设置
            $("#ModelTypeJudgeType").val(_data.ModelTypeJudgeType);
            if (_data.UseModelTypeOption) {
                $("#UseModelTypeOption").prop("checked", "true");
                $("#modelTypeContent").show();
                //生成已选型号
                $("#productModelsSelected").html(_data.ModelsHtml);
            }
             $("#ScreenTypeJudgeType").val(_data.ScreenTypeJudgeType);
             if (_data.UseScreenTypeOption) {
                 $("#UseScreenTypeOption").prop("checked", "true");
                 $("#screenTypeContent").show();
                 //生成屏幕类型
                 for (let i = 0, j = _data.InsuranceProductsAvailableScreenType.length; i < j; i++) {
                     $("input[name='AvailableScreenType'][value='" + _data.InsuranceProductsAvailableScreenType[i] + "']").prop("checked", "true");
                 }
            }
            if (_data.UsePriceOption) {
                $("#UsePriceOption").prop("checked", "true");
                $("#ProductAmountFrom").val(_data.ProductAmountFrom).removeAttr("disabled");
                $("#ProductAmountTo").val(_data.ProductAmountTo).removeAttr("disabled");

            }
            //审核项目配置
            for (let i = 0, j = _data.InsuranceProductsAuditProjectConfigurationMappings.length; i < j; i++) {
                let item = _data.InsuranceProductsAuditProjectConfigurationMappings[i];
                let ele = $(".useAuditProject[value='" + item.AuditProjectConfigurationID + "']");
                ele.prop("checked", "true");
                if (item.IsMust) {
                    ele.parent("td").parent("tr").find(".auditProjectIsMust").prop("checked", "true");
                }
                ele.parent("td").parent("tr").prevAll(".firstParent").eq(0).find(".open").click();
            }
            //信息收集项目配置
            for (let i = 0, j = _data.InsuranceProductsInfoCollectItemMappings.length; i < j; i++) {
                let item=_data.InsuranceProductsInfoCollectItemMappings[i];
                let ele = $(".useInfoCollect[value='" + item.CollectTypeCollectItemMappingID + "']");
                ele.prop("checked", "true");
                ele.parent("td").parent("tr").find(".infoCollectNumber").val(item.CanUploadPicCount);
                if (item.IsMust)
                {
                    ele.parent("td").parent("tr").find(".infoCollectIsMust").prop("checked", "true");
                }
                ele.parent("td").parent("tr").prevAll(".firstParent").eq(0).find(".open").click();
            }
        }

        //生成服务项目表格列表HTML
        function setServiceProjectHtml(_data)
        {
            let _html = '<tr class="serviceProjectItem" data=\'' + JSON.stringify(_data) + '\' ServiceProjectId="' + _data.ServiceProjectId + '">';
            _html += '<td>手机维修服务</td>';
            _html += '<td>' + _data.ServiceProjectName + '</td>';
            _html += '<td>' + _data.ServiceTimes + '</td>';
            _html += '<td><a href="#" onclick=\'editServiceProject(this,"cellPhone")\'>编辑</a> | <a href="#" onclick=\'deleteServiceProject(this,"cellPhone")\'>删除</a></td>';
            _html += '</tr>';
            return _html;
        }

        //$(function () {
        //    $("#ParentID").chosen();
        //    $("#ActionListId").chosen();
        //});
    </script>
}

